package com.efast.dmom.mgmt.service.mes.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.efast.cafe.framework.bean.ResultBean;
import com.efast.dmom.mgmt.bean.mes.ReportAcceptBean;
import com.efast.dmom.mgmt.bean.mes.ReportQueryBean;
import com.efast.dmom.mgmt.dao.mes.ReportQueryDao;
import com.efast.dmom.mgmt.service.mes.ReportQueryService;
@Service
public class ReportQueryServiceImpl implements ReportQueryService {
	
	@Autowired
	private ReportQueryDao reportQueryDao;

	@Override
	public ResultBean productQualityQuestion(ReportQueryBean reportQueryBean) {
		ResultBean resultBean = new ResultBean();
		String requestAnalysys = reportQueryBean.getRequestAnalysys();
		if(reportQueryBean.getMonth()!=null && reportQueryBean.getMonth().length >0) {
		reportQueryBean.setStartMonth(reportQueryBean.getMonth()[0]);
		reportQueryBean.setEndMonth(reportQueryBean.getMonth()[1]);
		}
		if (requestAnalysys.equals("检测项")) {
			List<ReportAcceptBean> productQualityQuestionByItem = reportQueryDao.productQualityQuestionByItem(reportQueryBean);
			resultBean.setSuccess(true);
			resultBean.setObject(productQualityQuestionByItem);
		} else if (requestAnalysys.equals("缺陷")) {
			resultBean.setSuccess(true);
			List<ReportAcceptBean> productQualityQuestionByDefect = reportQueryDao.productQualityQuestionByDefect(reportQueryBean);
			resultBean.setObject(productQualityQuestionByDefect);
		} else if (requestAnalysys.equals("零部件名称")) {
			resultBean.setSuccess(true);
			List<ReportAcceptBean> productQualityQuestionByPart = reportQueryDao.productQualityQuestionByPart(reportQueryBean);
			resultBean.setObject(productQualityQuestionByPart);
		} else {
			resultBean.setSuccess(false);
			resultBean.setMessage("无法找到指定选择项");
		}
		return resultBean;
	}

	@Override
	public ResultBean selectAllStation() {
		// TODO Auto-generated method stub
		List<String> selectAllStation = reportQueryDao.selectAllStation();
		ResultBean resultBean = new ResultBean();
		resultBean.setSuccess(true);
		resultBean.setObject(selectAllStation);
		return resultBean;
	}

	@Override
	public ResultBean selectAllCarType() {
		// TODO Auto-generated method stub
		List<String> selectAllCarType = reportQueryDao.selectAllCarType();
		ResultBean resultBean = new ResultBean();
		resultBean.setSuccess(true);
		resultBean.setObject(selectAllCarType);
		return resultBean;
	}

	@Override
	public ResultBean selectAllVin() {
		// TODO Auto-generated method stub
		List<Map<String,String>> selectAllVin = reportQueryDao.selectAllVin();
		ResultBean resultBean = new ResultBean();
		resultBean.setSuccess(true);
		resultBean.setObject(selectAllVin);
		return resultBean;
	}

	@Override
	public ResultBean selectAllPartName() {
		List<Map<String,String>> selectAllPartName = reportQueryDao.selectAllPartName();
		ResultBean resultBean = new ResultBean();
		resultBean.setSuccess(true);
		resultBean.setObject(selectAllPartName);
		return resultBean;
	}
	
	@Override
	public ResultBean qualityQuestionSearch(ReportQueryBean reportQueryBean) {
		ResultBean resultBean = new ResultBean();
		String requestAnalysys = reportQueryBean.getRequestAnalysys();
		if(reportQueryBean.getMonth()!=null && reportQueryBean.getMonth().length >0) {
			reportQueryBean.setStartMonth(reportQueryBean.getMonth()[0]);
			reportQueryBean.setEndMonth(reportQueryBean.getMonth()[1]);
		}
		if (requestAnalysys.equals("物料名称")) {
			resultBean.setSuccess(true);
			List<ReportAcceptBean> selectPartByCarType = reportQueryDao.selectPartByCarType(reportQueryBean);
			resultBean.setObject(selectPartByCarType);
		} else if (requestAnalysys.equals("供应商")) {
			resultBean.setSuccess(true);
			List<ReportAcceptBean> selectSupperlierByCarType = reportQueryDao.selectSupperlierByCarType(reportQueryBean);
			resultBean.setObject(selectSupperlierByCarType);
		} else if (requestAnalysys.equals("物料等级")) {
			resultBean.setSuccess(true);
			List<ReportAcceptBean> selectQuestionByCarType = reportQueryDao.selectPartLevelByCarType(reportQueryBean);
			resultBean.setObject(selectQuestionByCarType);
		} else if (requestAnalysys.equals("问题描述")) {
			resultBean.setSuccess(true);
			List<ReportAcceptBean> selectQuestionByCarType = reportQueryDao.selectQuestionByCarType(reportQueryBean);
			resultBean.setObject(selectQuestionByCarType);
		} else if (requestAnalysys.equals("问题等级")) {
			resultBean.setSuccess(true);
			List<ReportAcceptBean> selectQuestionLevelByCarType = reportQueryDao.selectQuestionLevelByCarType(reportQueryBean);
			resultBean.setObject(selectQuestionLevelByCarType);
		} else if (requestAnalysys.equals("问题类型")) {
			resultBean.setSuccess(true);
			List<ReportAcceptBean> selectQuestionTypeByCarType = reportQueryDao.selectQuestionTypeByCarType(reportQueryBean);
			resultBean.setObject(selectQuestionTypeByCarType);
		} else if (requestAnalysys.equals("处置结果")) {
			resultBean.setSuccess(true);
			List<ReportAcceptBean> selectDealResultByCarType = reportQueryDao.selectDealResultByCarType(reportQueryBean);
			resultBean.setObject(selectDealResultByCarType);
		} else {
			resultBean.setSuccess(false);
			resultBean.setObject("无法找到对应字段！");
		}
		return resultBean;
	}

	@Override
	public ResultBean saleQuestion(ReportQueryBean reportQueryBean) {
		ResultBean resultBean = new ResultBean();
		String requestAnalysys = reportQueryBean.getRequestAnalysys();
		if(reportQueryBean.getMonthAndYear()!=null && reportQueryBean.getMonthAndYear().length >0) {
			reportQueryBean.setStartMonth(reportQueryBean.getMonthAndYear()[0]);
			reportQueryBean.setEndMonth(reportQueryBean.getMonthAndYear()[1]);
		}
		if (requestAnalysys.equals("故障类型")) {
			resultBean.setSuccess(true);
			List<ReportAcceptBean> selectdefectType = reportQueryDao.selectdefectType(reportQueryBean);
			resultBean.setObject(selectdefectType);
		} else if (requestAnalysys.equals("故障部件")) {
			resultBean.setSuccess(true);
			List<ReportAcceptBean> selectdefectPart = reportQueryDao.selectdefectPart(reportQueryBean);
			resultBean.setObject(selectdefectPart);
		} else if (requestAnalysys.equals("区域")) {
			resultBean.setSuccess(true);
			List<ReportAcceptBean> selectArea = reportQueryDao.selectArea(reportQueryBean);
			resultBean.setObject(selectArea);
		} else if (requestAnalysys.equals("故障描述")) {
			resultBean.setSuccess(true);
			List<ReportAcceptBean> selectDefectDescribe = reportQueryDao.selectDefectDescribe(reportQueryBean);
			resultBean.setObject(selectDefectDescribe);
		} else if (requestAnalysys.equals("责任单位")) {
			resultBean.setSuccess(true);
			List<ReportAcceptBean> selectAccountable = reportQueryDao.selectAccountable(reportQueryBean);
			resultBean.setObject(selectAccountable);
		} else {
			resultBean.setSuccess(false);
			resultBean.setObject("无法  对应字段！");
		}
		return resultBean;
	}

	@Override
	public ResultBean qualityQuestionCar() {
		ResultBean resultBean = new ResultBean();
		List<String> selectAllIqcModel = reportQueryDao.selectAllIqcModel();
		resultBean.setObject(selectAllIqcModel);
		return resultBean;
	}

	@Override
	public ResultBean saleAfterQuestionCarType() {
		ResultBean resultBean = new ResultBean(true,"执行成功");
		List<String> selectAllSaleAfterModel = reportQueryDao.selectAllSaleAfterModel();
		resultBean.setObject(selectAllSaleAfterModel);
		return resultBean;
	}

	@Override
	public ResultBean saleAfterQuestionVIN() {
		ResultBean resultBean = new ResultBean(true,"执行成功");
		List<String> saleAfterQuestionVIN = reportQueryDao.selectAllSaleAfterVIN();
		resultBean.setObject(saleAfterQuestionVIN);
		return resultBean;
	}


}
